package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategySign;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.StrategySignMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategySignService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.UCDecoder;

import java.util.Date;
import java.util.List;

@Service
public class StrategySignServiceImpl implements IStrategySignService {
    @Autowired
    private StrategySignMapper strategySignMapper;


    @Override
    public StrategySign get(Long id) {
        return strategySignMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<StrategySign> listAll() {
        return strategySignMapper.selectAll();
    }

    @Override
    public void save(StrategySign strategySign) {
        //设置点赞或者收藏的时间
        if (strategySign.getGreatStatus() != null) {
            strategySign.setGreatTime(new Date());
        }
        if (strategySign.getEnshrineStatus() != null) {
            strategySign.setEnshrineTime(new Date());
        }
        strategySignMapper.insert(strategySign);
    }

    @Override
    public void update(StrategySign strategySign) {
        //设置点赞或者收藏的时间
        if (strategySign.getGreatStatus() != null) {
            strategySign.setGreatTime(new Date());
        }
        if (strategySign.getEnshrineStatus() != null) {
            strategySign.setEnshrineTime(new Date());
        }
        strategySignMapper.updateByPrimaryKey(strategySign);

    }


    @Override
    public PageInfo queryForList(QueryObject qo) {
        return null;
    }

    @Override
    public void updateState(StrategySign strategySign) {

    }


    /**
     * 根据大攻略id查询当前用户的在该攻略下的标记状态
     *
     * @param strategyId
     * @return
     */
    @Override
    public StrategySign selectByStrategyId(Long strategyId, Long userId) {

        return strategySignMapper.selectByStrategyId(strategyId, userId);
    }

    @Override
    public int queryGreatStatusCountByStrategyId(Long strategyId) {

        return strategySignMapper.queryGreatStatusCountByStrategyId(strategyId);
    }

    @Override
    public int queryEnshrineStatusCountByStrategyId(Long strategyId) {
        return strategySignMapper.queryEnshrineStatusCountByStrategyId(strategyId);
    }


}
